package icu.d4peng.basic.http.feign.loadbalancer;

import java.io.ByteArrayInputStream;
import java.net.URI;

import feign.Response;

import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeException;

/**
 * @author d4peng d4peng@qq.com
 * @date 2023-11-26 15:36:16
 */

public class LoadBalancerResponseStatusCodeException extends RetryableStatusCodeException {

	private final Response response;

	public LoadBalancerResponseStatusCodeException(String serviceId, Response response, byte[] body, URI uri) {
		super(serviceId, response.status(), response, uri);
		this.response = Response.builder()
			.body(new ByteArrayInputStream(body), body.length)
			.headers(response.headers())
			.reason(response.reason())
			.status(response.status())
			.request(response.request())
			.build();
	}

	@Override
	public Response getResponse() {
		return this.response;
	}

}
